﻿using Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public class TimeSystem : EntitySystem, IAwake
    {
        public void Awake()
        {
            Subscribe<GetSecondsTimestamp>(GetSecondsTimestamp);
            Subscribe<GetMillisecondsTimestamp>(GetMillisecondsTimestamp);
        }

        private void GetMillisecondsTimestamp(ref GetMillisecondsTimestamp data)
        {
            DateTimeOffset now = (DateTimeOffset)DateTime.UtcNow;
            data.millisecondsTimestamp = now.ToUnixTimeMilliseconds();
        }

        private void GetSecondsTimestamp(ref GetSecondsTimestamp data)
        {
            DateTimeOffset now = (DateTimeOffset)DateTime.UtcNow;
            data.secondsTimestamp = (uint)now.ToUnixTimeSeconds();
        }
    }

    public struct GetMillisecondsTimestamp : IEventData
    {
        public long millisecondsTimestamp;
    }

    public struct GetSecondsTimestamp : IEventData
    {
        public uint secondsTimestamp;
    }
}
